data{
  int<lower=1> J; // Total Number of Agency--Years
  int<lower=1> K; // Total Number of Indicators
  int<lower=1> N; // Total Number of Observations
  int<lower=1,upper=J> jj[N]; //Agency--Year for Observation N
  int<lower=1,upper=K> kk[N]; //Indicator for Observation N
  real y[N]; //Value of indicator for Observation N
}
parameters{
vector[J] alpha; //Capacity for Agency-Year J
vector<lower=0>[K] beta1; //Intercept 
vector<lower=0>[K] beta2; //Difficulty for Indicator K
vector<lower=0>[K] gamma; //Discrimination of K
real<lower=0, upper=10> sigma; //Population SD
}
transformed parameters{
vector[N] theta; //Agency--Year Effects
real tau;
theta = gamma[kk] .* (beta1[kk]+(beta2[kk] .* alpha[jj]));
tau = pow(sigma,-2);
}
model{
alpha ~ normal(0,10); //Priors for Capacity
beta1 ~ normal(0,10); //Prior of Intercept
beta2 ~ normal(0,10); //Prior of Difficulty
gamma ~ normal(0,10); //Prior of Discrimination
sigma ~ uniform(0,10); //Prior for Sigma
y ~ normal(theta,tau);
 }